﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win8Demo.DataModel;
using Windows.Data.Json;

namespace Win8Demo.Parser
{
    public class HoneyParser : BaseParser
    {
        public override void ParseData(JsonObject source, Dictionary<string, object> resultData)
        {
            if (source != null && resultData != null && resultData.ContainsKey("HoneyList"))
            {
                List<HoneyEntity> honeyList = resultData["HoneyList"] as List<HoneyEntity>;
                JsonArray array = source.GetArray();
                foreach (IJsonValue current in array)
                {
                    try
                    {
                        JsonObject jsonObject = current.GetObject();
                        HoneyEntity honeyEntity = new HoneyEntity();
                        honeyEntity.ID = jsonObject.GetNamedString("id");
                        honeyEntity.ImageUrl = jsonObject.GetNamedString("imageUrlForIphone");
                        honeyEntity.ImgRatio = jsonObject.GetNamedString("imgRatio");
                        honeyEntity.Name = jsonObject.GetNamedString("name"); 
                        honeyEntity.Price = jsonObject.GetNamedString("price");
                        honeyEntity.Timestamp = jsonObject.GetNamedNumber("timestamp");
                        honeyList.Add(honeyEntity);
                    }
                    catch
                    { 

                    }
                }
                if (this._nextParser != null)
                {
                    _nextParser.ParseData(source, resultData);
                }
            }
        }
    }
}
